﻿Imports System.Collections.ObjectModel
Imports System.ComponentModel
Public Class ExpenseTypeList
    Inherits ObservableCollection(Of ExpenseTypeClass)
    Dim expenseTypeDB As New IETrackerDataClassesDataContext
    Private Shared list As New ExpenseTypeList

    Public Shared Function GetList() As ExpenseTypeList
        Return list
    End Function

    Private Sub New()
        ' Make the constructor private, enforcing the 
        ' "factory" concept -- the only way to create
        ' an instance of this class is by calling
        ' the GetList method.
        AddItems()
    End Sub

    Public Shared Sub Reset()
        list.ClearItems()
        list.AddItems()
    End Sub

    Private Sub AddItems()
        Dim expenses = From xList In expenseTypeDB.TransactionDescriptions _
                          Join tt In expenseTypeDB.TransactionTypes _
                          On xList.TransactionDescriptionID Equals tt.TransactionDescID _
                          Where tt.TransactionTypeDescID = 2 _
                          Select TransactionDescription = xList.TransactionDescription, _
                          TransactionDescriptionID = xList.TransactionDescriptionID _
                          , isAuto = xList.IsAutoDeduct _
                                                    Distinct


        For Each pItem In expenses '.ToList '.OrderByDescending(Function(x) x.trans.TransactionDate)
            With pItem
                Add(New ExpenseTypeClass(.TransactionDescriptionID _
                                      , .TransactionDescription _
                                      , .isAuto))
            End With

        Next
    End Sub
End Class
